#!/bin/bash

#file_input=/var/lib/dhcp3/dhclient.eth0.leases
file_input=/home/dhclient.eth0.leases

file_length=`wc -l $file_input | cut -d " " -f 1`
last_lease_pos=`cat $file_input | grep -n "lease {" | cut -d ":" -f 1 | sort -r | head -n 1`
tail_length=$(($file_length - $last_lease_pos+1))
lease_services=`tail -n $tail_length $file_input | grep "disabled-services" | cut -d " " -f 5-99`

echo "Lease Services: $lease_services"

if echo "$lease_services" | grep -q "web"
then
  echo "Not starting Lighttpd (Web) interface"
else
  echo "Starting Lighttpd (Web) interface"
fi

if echo "$lease_services" | grep -q "lirc"
then
  echo "Not starting LIRC (IR) interface"
else
  echo "Starting LIRC (IR) interface"
fi
